package com.shengqiang.zhenhuiTransfer.config;

import com.baomidou.mybatisplus.mapper.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Component
public class MyMetaObjectHandler extends MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        Object createTimeObj=getFieldValByName("createTime",metaObject);
        if(createTimeObj==null){
            LocalDateTime localDate=LocalDateTime.now();
            DateTimeFormatter formatter=DateTimeFormatter.ofPattern("yyyy-MM-dd");
            String nowDateTime=localDate.format(formatter);
            setFieldValByName("createTime",nowDateTime,metaObject);
        }
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        insertFill(metaObject);
    }
}
